package hrms.util.amq;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class TopicPublisher {

	
	public boolean sendMessage(String text) {
		ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
		Connection connection = null;
		try {
			connection = factory.createConnection();
			connection.start();
			Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
			Topic topic = session.createTopic("Aikes.Topic");
	
			MessageProducer producer = session.createProducer(topic);
			producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
	
			TextMessage message = session.createTextMessage();
			message.setText(text);
			producer.send(message);
		} catch (JMSException e1) {
			e1.printStackTrace();
			return false;
		} finally {
			try {
				connection.close();
			} catch (JMSException e) {
				e.printStackTrace();
			}
		}
		return true;

	}
	public static void main(String[] args) {
//		new TopicPublisher().sendMessage();
	}
}